package com.howinfun.schedule;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.howinfun.common.Result;
import com.howinfun.netty.pool.ClientChannelPool;
import com.howinfun.utils.BaseUtils;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Map;

@Slf4j
@Component
public class AlipayTimer {


    /**
     * @Param:
     * @Return: 
     * @Author: chizon
     * @Date: 2019/8/20
    **/
    @Scheduled(cron = "0 0/5 * * * ?")
    public void mnoitor(){
        Map<String, Channel> channelMap = ClientChannelPool.getChannels();
        for(Map.Entry<String, Channel> entry : channelMap.entrySet()){
            String mapKey = entry.getKey();
            Channel mapValue = entry.getValue();
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("mark",BaseUtils.createOrderId());
            jsonObject.put("money","1.00");
            jsonObject.put("key_id","0");
            jsonObject.put("messageuuid","mid" + BaseUtils.createOrderId());
            jsonObject.put("paytype","alipay");
            jsonObject.put("type","paytype");
            log.info("clientId:{} msg:{}",mapKey,JSON.toJSONString(jsonObject));
            mapValue.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(jsonObject)));
        }
    }


}